<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" label-width="140px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="医院名称">
              <hospitalListbth @childfun="childfun" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="银行卡号">
              <el-input v-model="params.bankCard" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="审核状态">
              <el-select v-model="params.auditStatus" placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button style="margin-left:60px" type="primary" @click="search">查询</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div class="listDiv">
      <!-- table列表 -->
      <el-table :data="tableData" class="tableData" style="width: 100%">
        <el-table-column
          type="index"
          label="序号"
          fixed="left"
          align="center"
          :index="table_index"
          width="50"
        />
        <el-table-column prop="targetName" label="医院名称" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.targetId | hospitalName(hlist)}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="bankName" label="银行名称" align="center" />
        <el-table-column prop="bankCard" label="银行卡号" align="center" />
        <el-table-column prop="bankAccountName" label="户名" align="center" />
        <el-table-column prop="bankBranchName" label="开户行支行" align="center" />
        <el-table-column prop="mobileId" label="手机号码" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.mobileId |phonereg}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createdAt" label="绑定时间" align="center" />
        <el-table-column label="审核状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.auditStatus ==0">待审核</span>
            <span v-if="scope.row.auditStatus ==1">审核通过</span>
            <span v-if="scope.row.auditStatus ==2">
              审核驳回
              <p>驳回原因：{{scope.row.remark}}</p>
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="approvedTime" label="审核通过时间" align="center" />
        <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.auditStatus ==0 && permissionJson.indexOf('AdminMerchantBankcardProvider.audit') !=-1"
              type="text"
              size="small"
              @click="edit(scope.row,1)"
            >审核</el-button>
            <el-button
              v-if="permissionJson.indexOf('AdminMerchantBankcardProvider.getMerchantBankcard') !=-1 || scope.row.auditStatus ==2"
              type="text"
              size="small"
              @click="edit(scope.row,0)"
            >查看</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="params.pageNum"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="params.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import hospitalListbth from "@/components/hospitalList";
import checkbrank from "@/api/checkbrank";
import paylist from "@/api/paylist";
import filters from "@/assets/filter.js";
export default {
  components: {
    hospitalListbth
  },
  data() {
    return {
      permissionJson: JSON.parse(localStorage.getItem("permissionJson")),
      options: [
        {
          value: "0",
          label: "待审核"
        },
        {
          value: "1",
          label: "审核通过"
        },
        {
          value: "2",
          label: "审核驳回"
        }
      ],
      tableData: [],
      total: 0,
      time: "",
      hlist: [],
      params: {
        auditStatus: "",
        pageNum: 1,
        pageSize: 20,
        targetId: "",
        bankCard: ""
      }
    };
  },
  mounted() {
    this.hospitallist();
  },
  methods: {
    search() {
      this.params.pageNum = 1;
      this.list();
    },
    async hospitallist() {
      let res = await paylist.hostlist();
      if (res.data.code == 0) {
        this.hlist = res.data.data;
        this.list();
      }
    },
    list() {
      checkbrank.listMerchantBankcards(this.params).then(res => {
        console.log(res);
        if (res.data.code == 0) {
          this.tableData = res.data.data.list;
          this.total = res.data.data.count;
        } else {
          this.$message.warning(res.data.msg);
        }
      });
    },
    edit(datas, type) {
      if (type == 0) {
        // 详情
        this.$router.push({
          name: "mangeHospitalinfo",
          query: { type: type, id: datas.cardId }
        });
      }
      if (type == 1) {
        // 详情
        this.$router.push({
          name: "mangeHospitalcheck",
          query: { type: type, id: datas.cardId }
        });
      }
    },
    childfun(res) {
      this.params.targetId = res.id + "";
    },
    handleSizeChange(val) {
      this.params.pageNum = 1;
      this.params.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.list();
    },
    table_index(index) {
      return (this.params.pageNum - 1) * this.params.pageSize + index + 1;
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
</style>
